<template>
  <div
    class="swiper-item"
    :class="[activeSwiper === item.name ? 'active' : '']"
    @click="swiperChange(item)"
  >
    <div class="item-ring" ref="ring"></div>
    <div style="text-align: center">A工厂</div>
  </div>
</template>
<script>
import *as  echarts from 'echarts'
export default {
  name: "ring2",
  emits: ["swiperChange"],
  props: {
    activeSwiper: String,
    item: Object
  },
  methods: {
    swiperChange(val) {
      this.$emit("swiperChange", val);
    },
    init() {
      let chart = echarts.init(this.$refs.ring);
      let option = {
        title: {
          text: this.item.value + "%",
          x: "center",
          top: "45%",
          textStyle: {
            fontSize: "20"
          }
        },
        tooltip: {
          trigger: "item"
        },
        legend: {
          show: false
        },
        polar: {
          center: ["50%", "50%"],
          radius: ["60%", "80%"]
        },
        angleAxis: {
          max: 100,
          show: false
        },
        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          }
        },
        series: [
          {
            data: [this.item.value],
            name: "",
            type: "bar",
            roundCap: false,
            showBackground: true,
            backgroundStyle: {
              color: "#ddd"
            },
            coordinateSystem: "polar",
            itemStyle: {
              normal: {
                color: "#005DCF"
              }
            }
          }
        ]
      };
      chart.setOption(option);
      window.onresize = () => {
        chart.resize();
      };
    }
  },
  mounted() {
    this.init();
  }
};
</script>

<style scoped lang="scss">
.swiper-item {
  width: calc(100% / 9);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  &.active {
    background: #e6eefd;
    border-top: 2px solid #5eb3f0;
  }
  .item-ring {
    width: 100%;
    height: 80%;
  }
}
</style>
